<?php
/*
	插件概览
	分销插件主要显示哪些数据？
		1、基本数据
		分销订单总数 会员总数 分销商总数 
		分销订单近七天增长趋势折线图 会员数近七天增长折线图 分销商近七天增长折线图 
		释放总笔数/金额 结算总笔数/金额
		饼状图显示各状态释放数额  饼状图显示各状态结算总笔数/金额
		
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'welcome';
$tabs=array(
	array('op'=>'welcome','title'=>'概况'),
	array('op'=>'line','title'=>'趋势'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='welcome'){
	//会员
	$member=array(
		'area_member'=>$this->count('area_member',array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>0)),
		'agent'=>$this->count('area_member',array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>1)),
		'stop'=>$this->count('area_member',array('uniacid'=>$_SESSION['uniacid'],'stop'=>1)),
	);
	$return['htmls'][]=array('type'=>'data','one_num'=>4,'title'=>'会员概况','datas'=>array(
		array('title'=>'会员数量','num'=>1,'data'=>$member['area_member']),
		array('title'=>'分销商数量','num'=>1,'data'=>$member['agent']),
		array('title'=>'黑名单','num'=>1,'data'=>$member['stop']),
	));
	//释放
	$month_start=strtotime(date('Ym').'01');
	$commission_month['num']=$this->count('commission',array('type >'=>2,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$commission_month['money']=$this->sum('commission',array('type >'=>2,'uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'money');
	$commission['num']=$this->count('commission',array('type >'=>2,'uniacid'=>$_SESSION['uniacid']));
	$commission['money']=$this->sum('commission',array('type >'=>2,'uniacid'=>$_SESSION['uniacid']),'money');
	//结算
	$balance_month['num']=$this->count('balance',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$balance_month['money']=$this->sum('balance',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'money');
	$balance['num']=$this->count('balance',array('uniacid'=>$_SESSION['uniacid']));
	$balance['money']=$this->sum('balance',array('uniacid'=>$_SESSION['uniacid']),'money');
	$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'释放概况','datas'=>array(
		array('title'=>'释放笔数/金额','num'=>2,'data'=>array($commission['num'],$commission['money'])),
		array('title'=>'结算笔数/金额','num'=>2,'data'=>array($balance['num'],$balance['money'])),
		array('title'=>'本月释放笔数/金额','num'=>2,'data'=>array($commission_month['num'],$commission_month['money'])),
		array('title'=>'本月结算笔数/金额','num'=>2,'data'=>array($balance_month['num'],$balance_month['money'])),
	));
	
	$commission_pie=array(
		'title'=>'释放概况',
		'tablename'=>$this->tablename('commission'),
		'width'=>'50%',
		'field'=>'status',
		'field_options'=>$this->commission_status,
		'params'=>array('type >'=>2,'uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($commission_pie);
	$balance_pie=array(
		'title'=>'结算订单概况',
		'tablename'=>$this->tablename('balance'),
		'width'=>'50%',
		'field'=>'status',
		'field_options'=>$this->balance_status,
		'params'=>array('uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($balance_pie);
	set_html('title','分销概况');
	exi($return);
}
if($_RQ['op']=='line'){
	//趋势
	$order_params=array(
		'title'=>'近30天分销订单走势',
		'data'=>array(
			'tablename'=>$this->tablename('fee_order'),
		),
	);
	$return['htmls'][]=model('core/echart')->line($order_params);
	$member_params=array(
		'title'=>'近三十天会员/分销商增长走势',
		'data'=>array(
			'会员增长'=>array(
				'tablename'=>$this->tablename('area_member'),
			),
			'分销商增长'=>array(
				'tablename'=>$this->tablename('area_member'),
				'params'=>array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>1),
				'time_field'=>'agenttime',
			)
		),
	);
	$return['htmls'][]=model('core/echart')->line($member_params);
	set_html('title','分销趋势');
	exi($return);
}